<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
    <script src="/static/jquery.js"></script>
</head>
<style>
    .xz {
        margin-left: -500px
    }

    table {
        text-align: center;
    }
</style>
<body>

<div align="center">
    <h3>图书信息</h3>
    <form th:action="@{/books}" method="post">
        <div>
            书名:<input type="text" name="name" th:value="${name}">&nbsp;
            类目:<input type="text" name="category" th:value="${category}">&nbsp;
            作者:<input type="text" name="author" th:value="${author}">&nbsp;
            <input type="submit" value="查询">
        </div>
    </form>
    <div class="xz">
        <a th:href="@{/toAdd}">
            <input type="submit" value="新增图书信息">
        </a>
    </div>
    <form th:action="@{/getDel}" method="post" onsubmit="return delMel()">
        <table border="1" align="center">
            <tr>
                <th>选择</th>
                <th>编号</th>
                <th>书名</th>
                <th>价格</th>
                <th>类目</th>
                <th>库存</th>
                <th>图片</th>
                <th>说明</th>
                <th>作者</th>
                <th>已售</th>
                <th>操作</th>
            </tr>

            <tr th:each="book,sta:${list}">
                <td>
                    <input type="checkbox" name="ids" th:value="${book.id}">
                </td>
                <td th:text="${sta.count}"></td>
                <td th:text="${book.name}"></td>
                <td th:text="${book.price}"></td>
                <td th:text="${book.category}"></td>
                <td th:text="${book.pnum}"></td>
                <td th:text="${book.imgurl}"></td>
                <td th:text="${book.description}"></td>
                <td th:text="${book.author}"></td>
                <td th:text="${book.sales}"></td>
                <td>
                    <a th:href="@{/toUpdate/{id}(id=${book.id})}">修改</a>&nbsp;
                    <a th:href="@{/del/{id}(id=${book.id})}" onclick="return del()">删除</a>
                </td>
            </tr>
        </table>
        <div class="sc"><a><input type="submit" value="批量删除" onsubmit="return delMel()"></a></div>
    </form>
</div>

<script>
    function del() {
        if (confirm("确定要删除吗？")) {
            return true;
        } else {
            alert("取消操作")
            return false;
        }
    }

    function delMel(id) {
        if ($("input[name='ids']:checked").length == 0) {
            alert("请选择一项进行删除")
            return false;
        }
        if (confirm("确定要删除吗？")) {
            return true;
        } else {
            alert("取消操作")
            return false;
        }
    }
</script>
</body>
</html>